package com.web.treatment;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.Treatments;
import com.service.TreatmentsService;
import com.util.AuthenticateHttpServlet;

/**
 * Servlet implementation class ProductHandler
 */
@WebServlet("/Treatment/Create")
public class TreatmentCreate extends AuthenticateHttpServlet {
	private static final long serialVersionUID = 1L;

	protected void post(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			String code = request.getParameter("code");
			String name = request.getParameter("name");
			float salesPrice = Float.parseFloat(request
					.getParameter("salesPrice"));
			String description = request.getParameter("description");
			TreatmentsService service = new TreatmentsService();
			Treatments treatment = new Treatments();
			treatment.setTreatmentCode(code);
			treatment.setTreatmentName(name);
			treatment.setSalesPrice(salesPrice);
			treatment.setDescription(description);
			service.insertNewTreatment(treatment);
			request.getRequestDispatcher("/Treatment/List").forward(request,
					response);
		} catch (NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

}
